<!doctype html>
<html ng-app="app">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="../../build/common/base.css" rel="stylesheet">
<script type="text/javascript" src="../../build/common/base.js"></script>
<script type="text/javascript" src="../../build/common/ngEdit.js"></script>
</head>
<script type="text/javascript">
	var app = angular.module('app', [ 'baseDirective' ]);
	app.controller("ctrl", [ '$scope', 'baseService',
			function($scope, baseService) {

			} ]);

	app.directive('abUpload2',function(){//directive自定义指令，myHello是自定义指令的名字，函数是回调，

		return {
			restrict : 'AE',
			require : '?ngModel',
			scope : {
				ngModel : "="
			},
			link : function(scope, element, attrs, ngModel) {

				// Model数据更新时 在td 下增加按钮
				ngModel.$render = function() {
					if (!ngModel.$viewValue) {
						return;
					}
					var list = JSON.parse(ngModel.$viewValue);
					var parent = $(element).parent();
					// 增加没有的下载链接
					$.each(list, function(index, file) {
						// 已存在，不存在则增加
						if (parent.find("[fileId='"+file.id+"']").length > 0) {
							return;
						}
						var a = $("<a></a>");
						console.log(file)
						var href = __ctx + "/sys/sysFile/download?fileId=" + file.id;
							var img=$("<img></img>");
							img.attr("style","width: 200px; height: 200px");
							img.attr("src",href);
							a.append(img);
						a.attr("href", href);
						a.attr("fileId", file.id);
						a.attr("style", "margin-right:10px");
						$(element).before(a);
					});
					// 删除多余的没有的下载链接
					$.each(parent.find("a[fileId]"), function(index, a) {
						var exist = false;
						var fileId = $(a).attr("fileId");
						$.each(list, function(i, file) {
							if (file.id == fileId) {
								exist = true;
							}
						});
						if (!exist) {
							$(a).remove();
						}
					});

				};
			}
		}

	});
	/* 获取URL表单的 JSON 数据  必须以 getData为方法名*/
	function getData() {
		return AngularUtil.getScope().data;
	}
	
</script>
<body class="panel success" ng-controller="ctrl">
	<!-- 顶部按钮 -->
	<div class="panel-heading">
		<a href="javascript:void(0)" class="btn btn-sm btn-primary fa-reply" onclick="javascript:$.Dialog.close(window);"> 返回 </a>
	</div>
	<!--  ab-load 去controller 层获取业务数据  -->
	<form name="form" method="post" ab-load="crm/goods/get?id={id}"
		ng-model="data">

		<table class="form-table">
			<tbody>
				<tr>
					<th>商品名称</th>
					<td>{{data.name}}</td>
				</tr>
				<tr>
					<th>商品价格</th>
					<td>{{data.price}}</td>
				</tr>
				<tr>
					<th>商品积分</th>
					<td>{{data.credit}}</td>
				</tr>
				<tr>
					<th>商品图片</th>
					<td>
						<a href="javascript:void(0)"
						 ab-upload2=""
						ng-model="data.imgUrl"
						></a>
						
						
					</td>
				</tr>
				<tr>
					<th>商品库存</th>
					<td>{{data.inventory}}</td>
				</tr>
				<tr>
					<th>商品介绍</th>
					<td>
						{{data.detail}}
					</td>
				</tr>
			</tbody>
		</table>
		
		
				
	</form>

</body>
















</html>